import Mock from 'mockjs'
import { GetData, PostData } from '@/api'
import { MenuItem } from '@/types'

const baseURL = '/api'

Mock.setup({ timeout: 1000 })

// 登录模块接口
export const loginMocks = () => {
  const menus: MenuItem[] = [
    {
      id: 100000,
      parentId: null,
      name: '基础功能',
      path: '/JCGN_20000002'
    },
    {
      id: 10000001,
      parentId: 100000,
      name: '菜单管理',
      path: '/CDGL_10000001',
      filePath: 'basic/pageSet'
    },
    {
      id: 10000002,
      parentId: 100000,
      name: '页面管理',
      path: '/YMGL_10000002',
      filePath: 'basic/pageSet'
    },
    {
      id: 10000003,
      parentId: 100000,
      name: '数据看板',
      path: '/SJKB_10000003',
      filePath: 'basic/kanBan'
    },
    {
      id: 10000004,
      parentId: 100000,
      name: '低代码平台',
      path: '/DDMPT_10000004',
      filePath: 'lowCode/home'
    },
    {
      id: 2000000201,
      parentId: 20000002,
      name: '权限分配',
      path: '/QXFP_2000000201',
      filePath: 'BasicInfo/PowerDistribute'
    },
    {
      id: 200000,
      parentId: null,
      name: '系统管理',
      path: '/XTGL_200000'
    },
    {
      id: 20000001,
      parentId: 200000,
      name: '机构管理',
      path: '/ZZGL_20000001'
    },
    {
      id: 2000000101,
      parentId: 20000001,
      name: '组织机构',
      path: '/ZJJG_2000000101',
      filePath: 'system/organize'
    },
    {
      id: 2000000202,
      parentId: 20000002,
      name: '角色管理',
      path: '/JSGL_2000000202',
      filePath: 'BasicInfo/RoleManage'
    },
    {
      id: 20000003,
      parentId: 200000,
      name: '管理机构',
      path: '/GLJGXX_20000003'
    },
    {
      id: 2000000102,
      parentId: 20000001,
      name: '机构类型',
      path: '/ZZJGLX_2000000102',
      filePath: 'System/OrganizeType'
    },
    {
      id: 200000013,
      parentId: 200000,
      name: '菜单信息',
      path: '/CDXX_200000013',
      filePath: 'system/menuConfig'
    },
    {
      id: 2000000203,
      parentId: 20000002,
      name: '账号管理',
      path: '/ZHGL_2000000203',
      filePath: 'BasicInfo/AccountManage'
    },
    {
      id: 2000000104,
      parentId: 20000001,
      name: '人员类型',
      path: '/RYLXGL_2000000104',
      filePath: 'System/PeopleType'
    },
    {
      id: 20000005,
      parentId: 20000003,
      name: '管理机构',
      path: '/GLJG_20000005',
      filePath: 'User/UserLable'
    },
    {
      id: 2000000105,
      parentId: 20000001,
      name: '机构角色',
      path: '/JGJS_2000000105',
      filePath: 'BasicInfo/NodeRole'
    },
    {
      id: 200001,
      parentId: null,
      name: '工单管理',
      path: '/GDGL_200001'
    },
    {
      id: 20000301,
      parentId: 200001,
      name: '新建工单',
      path: '/XZGD_20000301',
      filePath: 'Manage/NewOrder'
    },
    {
      id: 20000302,
      parentId: 200001,
      name: '我的工单',
      path: '/WDGD_20000302',
      filePath: 'Manage/MyOrder'
    },
    {
      id: 20000303,
      parentId: 200001,
      name: '我的待办',
      path: '/WDDB_20000303',
      filePath: 'Manage/MyDealOrder'
    },
    {
      id: 20000304,
      parentId: 200001,
      name: '工单查询',
      path: '/GDCX_20000304',
      filePath: 'Manage/QueryOrder'
    },
    {
      id: 20000305,
      parentId: 200001,
      name: '工单跟踪',
      path: '/GDGZ_20000305',
      filePath: 'Manage/LogOrder'
    },
    {
      id: 200002,
      parentId: null,
      name: '表单设置',
      path: '/BDSZ_200002'
    },
    {
      id: 20000103,
      parentId: 200002,
      name: '类型设置',
      path: '/LXSZ_20000103',
      filePath: 'Manage/FormTypeManage'
    },
    {
      id: 2000014,
      parentId: 200002,
      name: '工单开启',
      path: '/GDKQ_2000014',
      filePath: 'Manage/OpenOrder'
    },
    {
      id: 20000102,
      parentId: 200002,
      name: '视图管理',
      path: '/STGL_20000102',
      filePath: 'Manage/ViewManage'
    },
    {
      id: 20000105,
      parentId: 200002,
      name: '流程管理',
      path: '/LCPZ_20000105',
      filePath: 'Manage/ProcessManage'
    },
    {
      id: 20000106,
      parentId: 200002,
      name: '工单类型',
      path: '/GDLX1_20000106',
      filePath: 'Manage/OrderTypeManage'
    },
    {
      id: 20000101,
      parentId: 200002,
      name: '表单管理',
      path: '/BDGL_20000101',
      filePath: 'Manage/FormManage'
    },
    {
      id: 20000104,
      parentId: 200002,
      name: '数据源配置',
      path: '/SJYPZ_20000104',
      filePath: 'Manage/DataSourceManage'
    },
    {
      id: 20000006,
      parentId: 20000003,
      name: '机构类型',
      path: '/GLJGLX_20000006',
      filePath: 'System/ManageType'
    },
    {
      id: 2000000103,
      parentId: 20000001,
      name: '人员管理',
      path: '/RYGL_2000000103',
      filePath: 'BasicInfo/PeopleManage'
    }
  ]

  // 登录接口
  Mock.mock(`${baseURL}/login`, {
    data: {
      token: '@string(20)',
      date: '@datetime'
    },
    status: true
  })

  // 获取菜单接口
  Mock.mock(`${baseURL}/getMenus`, {
    data: menus,
    status: true
  })

  const fLogin = (data: any): Promise<any> => {
    return PostData('/login', data)
  }

  const fGetMenus = (): Promise<any> => {
    return PostData('/getMenus', {})
  }

  return { fLogin, fGetMenus }
}

// 菜单接口
export const menuConfigMocks = () => {
  Mock.mock(`${baseURL}/getList`, {
    status: 200,
    'data|100': [
      {
        'key|+1': 20000,
        'id|+1': 0,
        username: 'dc00@integer(100000,999999)',
        paltName: '@pick(["统一管理中心", "丽水安全共治", "温州安全共治"])',
        name: '@cword(2,3)',
        mobile: /^1[3-9]\d{9}$/,
        status: '@pick(["正常", "停用"])',
        company: '@pick(["营销二部", "杭州分公司","游戏公司","摸鱼公司"])',
        type: '@pick(["管理员", "超级管理员","普通用户"])',
        source: '平台内注册平台内注册平台内注册平台内注册平台内注册',
        remark: '备注'
      }
    ]
  })

  type AccountList = <T>(data: any) => Promise<T>

  const getAccountList: AccountList = (data) => {
    return PostData('/getList', data)
  }

  return { getAccountList }
}

// 页面设置接口
export const pageSetMocks = () => {
  type PageList = <T>(data: any) => Promise<T>

  const getPageList: PageList = (data) => {
    return GetData('/getPageList', data)
  }

  return { getPageList }
}
